package cn.iocoder.yudao.module.pay.controller.app.walletwithdraw;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.pay.controller.admin.walletwithdraw.vo.PayWalletMetalWithdrawRespVO;
import cn.iocoder.yudao.module.pay.controller.admin.walletwithdraw.vo.PayWalletWithdrawPageReqVO;
import cn.iocoder.yudao.module.pay.controller.admin.walletwithdraw.vo.PayWalletWithdrawRespVO;
import cn.iocoder.yudao.module.pay.controller.app.walletwithdraw.vo.AppPayWalletWithdrawSaveReqVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.walletwithdraw.PayWalletWithdrawDO;
import cn.iocoder.yudao.module.pay.service.walletwithdraw.PayWalletWithdrawService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "用户app - 钱包提现")
@RestController
@RequestMapping("/pay/wallet-withdraw")
@Validated
public class AppPayWalletWithdrawController {

    @Resource
    private PayWalletWithdrawService walletWithdrawService;

    @PostMapping("/create")
    @Operation(summary = "创建钱包提现")
    public CommonResult<Long> createWalletWithdraw(@Valid @RequestBody AppPayWalletWithdrawSaveReqVO createReqVO) {
        return success(walletWithdrawService.createWalletWithdraw(createReqVO));
    }

    @PutMapping("/cancel")
    @Operation(summary = "取消钱包提现")
    public CommonResult<Boolean> updateWalletWithdraw(@RequestParam("id") Long id) {
        walletWithdrawService.cancelWalletWithdraw(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得钱包提现")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<PayWalletWithdrawRespVO> getWalletWithdraw(@RequestParam("id") Long id) {
        PayWalletWithdrawDO walletWithdraw = walletWithdrawService.getWalletWithdraw(id);
        return success(BeanUtils.toBean(walletWithdraw, PayWalletWithdrawRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得钱包提现分页")
    public CommonResult<PageResult<PayWalletWithdrawRespVO>> getWalletWithdrawPage(@Valid PayWalletWithdrawPageReqVO pageReqVO) {
        pageReqVO.setUserId(getLoginUserId());
        PageResult<PayWalletWithdrawDO> pageResult = walletWithdrawService.getWalletWithdrawPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, PayWalletWithdrawRespVO.class));
    }

    @GetMapping("/pickup-page")
    @Operation(summary = "获得钱包提现分页")
    public CommonResult<PageResult<PayWalletMetalWithdrawRespVO>> getWalletWithdrawPickupPage(@Valid PayWalletWithdrawPageReqVO pageReqVO) {
        PageResult<PayWalletMetalWithdrawRespVO> pageResult = walletWithdrawService.getWalletWithdrawPickupPage(pageReqVO);
        return success(pageResult);
    }


}